package ar.uba.fi.algo3.tp3.modelo;

import java.io.BufferedReader;
import java.io.IOException;

import java.io.InputStream;
import java.io.InputStreamReader;

public class ScannerMapa {

    private InputStream stream;
    private BufferedReader reader;

    public ScannerMapa(int nivel) {
        this.stream = this.getClass().getResourceAsStream("niveles/mapa"+nivel+".txt");
        this.reader = new BufferedReader(new InputStreamReader(stream));
    }

    public void cargarMapa(Mapa mapa) {
        char[] linea = new char[17];
        for (int i = 0; i < 16; i++) {
            try {
                linea = (reader.readLine().toCharArray());
            } catch (IOException e) {
            }
            for (int j = 0; j < 17; j++) {
                if (linea[j] == 'X') {
                    mapa.agregarPared(j * 30, i * 30);
                } else if (linea[j] == 'O') {
                    mapa.agregarPastilla(j * 30, i * 30);
                } else if (linea[j] == 'P') {
                    mapa.agregarPastillaPower(j * 30, i * 30);
                } else if (linea[j] == 'F') {
                    mapa.establecerCasaFantasmas(j * 30, i * 30);
                } else if (linea[j] == 'I') {
                    mapa.establecerCasaPacman(j * 30, i * 30);
                }
            }
        }
    }
}
